home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / data / happysrc / pcinsmbl.c < prev    next >
Text File  |  1993-11-30  |  28KB  |  713 lines

  1. /*********************************************************************
  2.  *
  3.  *      ***  HAPPy Pascal compiler ***
  4.  *          input symbol routine
  5.  *
  6.  *               void insymbol(void)
  7.  *                void real_err(int sig, int subcode)
  8.  *
  9.  *            copyright(c) H.Asano  1992,1993
  10.  *
  11.  *              return item -----
  12.  *                sy   : 要素のsymbol
  13.  *                op   : 要素の演算子タイプ
  14.  *                id   : 名標
  15.  *                ch   : 読込文字
  16.  *                lgth : 文字列等の長さ
  17.  *                val  : 数値
  18.  *
  19.  *********************************************************************/
  20.  
  21. #define EXTERN extern
  22.  
  23. #include <signal.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <jctype.h>
  28. #include "pascomp.h"
  29. #include "pcpcd.h"
  30.  
  31. /***** function prototype define ******/
  32.  
  33. extern void gen1(enum pcdmnc, int) ;
  34. extern void pcerr(int,char*);
  35. extern char *inttoch(long)  ;
  36. extern void term(void) ;
  37. extern void *Malloc(int) ;
  38. static void skipspace(void);
  39. static void nextch(void);
  40. static void identifier(void);
  41. static void innumber(void) ;
  42. static long chtoint(int,char*) ;
  43. static void strings(void) ;
  44. static void colonch(void);
  45. static void lparch(void);
  46. static void rparch(void);
  47. static void periodch(void);
  48. static void ltch(void);
  49. static void gtch(void);
  50. static void skipcomment(void);
  51. static void options(void)  ;
  52. static void specialch(void);
  53. static void illegch(void);
  54.  
  55.  
  56. /*****************************/
  57. /****      共通変数       ****/
  58. /*****************************/
  59.  
  60. extern FILE   *passource;  /* pascal ソースファイルポインタ */
  61.  
  62. /*****************************/
  63. /****      内部変数       ****/
  64. /*****************************/
  65.  
  66.  
  67. /***** pascal 予約語テーブル *****/
  68. static struct _reswd {
  69.        char          rw[10] ;           /* 予約語           */
  70.        enum symbol   rsy   ;            /* 予約語のsymbol   */
  71.        enum operator rop   ;            /* 予約語中の演算子 */
  72.     }  reswd[]  =     {
  73. /*lngh entno  (for frw table) */
  74. /*  2 *   0 */  {"if"       , ifsy     , noop },
  75. /*    *   1 */  {"do"       , dosy     , noop },
  76. /*    *   2 */  {"of"       , ofsy     , noop },
  77. /*    *   3 */  {"to"       , tosy     , noop },
  78. /*    *   4 */  {"in"       , relop    , inop },
  79. /*    *   5 */  {"or"       , addop    , orop },
  80. /*  3 *   6 */  {"end"      , endsy    , noop },
  81. /*    *   7 */  {"for"      , forsy    , noop },
  82. /*    *   8 */  {"var"      , varsy    , noop },
  83. /*    *   9 */  {"div"      , mulop    , idiv },
  84. /*    *  10 */  {"mod"      , mulop    , imod },
  85. /*    *  11 */  {"set"      , setsy    , noop },
  86. /*    *  12 */  {"and"      , mulop    , andop},
  87. /*    *  13 */  {"not"      , notsy    , noop },
  88. /*    *  14 */  {"nil"      , nilsy    , noop },
  89. /*  4 *  15 */  {"then"     , thensy   , noop },
  90. /*    *  16 */  {"else"     , elsesy   , noop },
  91. /*    *  17 */  {"with"     , withsy   , noop },
  92. /*    *  18 */  {"goto"     , gotosy   , noop },
  93. /*    *  19 */  {"case"     , casesy   , noop },
  94. /*    *  20 */  {"type"     , typesy   , noop },
  95. /*    *  21 */  {"file"     , filesy   , noop },
  96. /*  5 *  22 */  {"begin"    , beginsy  , noop },
  97. /*    *  23 */  {"until"    , untilsy  , noop },
  98. /*    *  24 */  {"while"    , whilesy  , noop },
  99. /*    *  25 */  {"array"    , arraysy  , noop },
  100. /*    *  26 */  {"const"    , constsy  , noop },
  101. /*    *  27 */  {"label"    , labelsy  , noop },
  102. /*  6 *  28 */  {"repeat"   , repeatsy , noop },
  103. /*    *  29 */  {"record"   , recordsy , noop },
  104. /*    *  30 */  {"downto"   , downtosy , noop },
  105. /*    *  31 */  {"packed"   , packedsy , noop },
  106. /*  7 *  32 */  {"program"  , progsy   , noop },
  107. /*  8 *  33 */  {"function" , funcsy   , noop },
  108. /*  9 *  34 */  {"procedure", procsy   , noop }
  109. } ;
  110.  
  111. static int frw[] = {0,0,6,15,22,28,32,33,34,35,35};
  112.     /*  予約語の長さで、予約語テーブルのサーチを高速化している */
  113.  
  114. /***** 読込み対象JISコード256種類を分類するためのテーブル *****/
  115.  
  116. enum  chtp {
  117.       letter,     /* 英字             */
  118.       number,     /* 数字             */
  119.       special,    /* 特殊文字         */
  120.       illegal,    /* 許されないコード */
  121.       chstrquo,   /* コーテーション   */
  122.       chcolon,    /* :  コロン        */
  123.       chperiod,   /* . ピリオド       */
  124.       chlt,       /* <  less than     */
  125.       chgt,       /* >  grater than   */
  126.       chlparen,   /* (  左かっこ      */
  127.       chrparen,   /* )  右かっこ      */
  128.       chcoment,   /* {  注釈開始      */
  129.       chspace     /* 空白             */
  130. } ;
  131. static struct  {
  132.        enum chtp     chartp    ;      /* 文字のタイプ  */
  133.        enum symbol   ssy       ;      /* 文字のsymbol  */
  134.        enum operator sop       ;      /* 文字中の演算子*/
  135.     }  chartb[256]  =    {
  136.  
  137.  /****** 00-1F : 制御コード  HT(09),LF(0A)はspace  それ以外はillegal *******/
  138.  /*00-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  139.  /*03-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  140.  /*06-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  141.  /*09-*/{chspace,othersy,noop}, {chspace,othersy,noop}, {illegal,othersy,noop},
  142.  /*0C-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  143.  /*0F-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  144.  /*12-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  145.  /*15-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  146.  /*18-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  147.  /*1B-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  148.  /*1E-*/{illegal,othersy,noop}, {illegal,othersy,noop},
  149.  
  150.    /****** 20-2F : 各種文字 ******/
  151.  /* sp  (20) */    {chspace,othersy,noop},
  152.  /* !   (21) */    {illegal,othersy,noop},
  153.  /* "   (22) */    {illegal,othersy,noop},
  154.  /* #   (23) */    {illegal,othersy,noop},
  155.  /* $   (24) */    {special,othersy,noop},
  156.  /* %   (25) */    {illegal,othersy,noop},
  157.  /* &   (26) */    {illegal,othersy,noop},
  158.  /* '   (27) */    {chstrquo,othersy,noop},
  159.  /* (   (28) */    {chlparen,lparent,noop},
  160.  /* )   (29) */    {chrparen,rparent,noop},
  161.  /* *   (2A) */    {special,mulop,mul},
  162.  /* +   (2B) */    {special,addop,plus},
  163.  /* ,   (2C) */    {special,comma,noop},
  164.  /* -   (2D) */    {special,addop,minus},
  165.  /* .   (2E) */    {chperiod,period,noop},
  166.  /* /   (2F) */    {special,mulop,rdiv},
  167.  
  168.    /****** 30-39: 数字 ******/
  169.  /*012*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  170.  /*345*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  171.  /*678*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  172.  /*9  */ {number,othersy,noop},
  173.  
  174.    /****** 3A-40 : 各種文字 ******/
  175.  /* :   (3A) */    {chcolon,colon,noop},
  176.  /* ;   (3B) */    {special,semicolon,noop},
  177.  /* <   (3C) */    {chlt,relop,ltop},
  178.  /* =   (3D) */    {special,relop,eqop},
  179.  /* >   (3E) */    {chgt,relop,gtop},
  180.  /* ?   (3F) */    {illegal,othersy,noop},
  181.  /* @   (40) */    {special,arrow,noop},  /* ^ の 代用 */
  182.  
  183.    /****** 41-5A : 英大文字 ******/
  184.  /*ABC*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  185.  /*DEF*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  186.  /*GHI*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  187.  /*JKL*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  188.  /*MNO*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  189.  /*PQR*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  190.  /*STU*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  191.  /*VWX*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  192.  /*YZ */ {letter,othersy,noop}, {letter,othersy,noop},
  193.  
  194.    /****** 5B-60 : 各種文字 ******/
  195.  /* [   (5B) */    {special,lbrack,noop},
  196.  /* \   (5C) */    {illegal,othersy,noop},
  197.  /* ]   (5D) */    {special,rbrack,noop},
  198.  /* ^   (5E) */    {special,arrow,noop},
  199.  /* _   (5F) */    {illegal,othersy,noop},
  200.  /* `   (60) */    {illegal,othersy,noop},
  201.  
  202.   /****** 61-7A : 英小文字 ******/
  203.  /*abc*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  204.  /*def*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  205.  /*ghi*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  206.  /*jkl*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  207.  /*mno*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  208.  /*pqr*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  209.  /*stu*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  210.  /*vwx*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  211.  /*yz */ {letter,othersy,noop}, {letter,othersy,noop},
  212.  
  213.    /****** 7B-7F : 各種文字 ******/
  214.  /* {   (7B) */    {chcoment,othersy,noop},
  215.  /* |   (7C) */    {illegal, othersy,noop},
  216.  /* }   (7D) */    {illegal, othersy,noop},
  217.  /*(7E-7F)*/       {illegal, othersy,noop}, {illegal,othersy,noop},
  218.  
  219.    /***** 80-FF : 各種記号 & カタカナ ******/
  220.  /*80-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  221.  /*83-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  222.  /*86-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  223.  /*89-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  224.  /*8C-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  225.  /*8F-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  226.  /*92-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  227.  /*95-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  228.  /*98-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  229.  /*9B-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  230.  /*9E-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  231.  /*A1-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  232.  /*A4-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  233.  /*A7-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  234.  /*AA-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  235.  /*AD-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  236.  /*B0-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  237.  /*B3-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  238.  /*B6-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  239.  /*B9-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  240.  /*BC-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  241.  /*BF-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  242.  /*C2-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  243.  /*C5-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  244.  /*C8-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  245.  /*CB-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  246.  /*CE-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  247.  /*D1-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  248.  /*D4-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  249.  /*D7-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  250.  /*DA-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  251.  /*DD-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  252.  /*E0-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  253.  /*E3-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  254.  /*E6-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  255.  /*E9-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  256.  /*EC-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  257.  /*EF-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  258.  /*F2-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  259.  /*F5-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  260.  /*F8-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  261.  /*FB-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  262.  /*FE-*/{illegal,othersy,noop}, {illegal,othersy,noop}
  263.  };
  264.  
  265. static boolean eolnflag    = true  ;    /* EOLN検出時 true            */
  266. static boolean period2flag = false ;    /* 数字処理中 ".." 検出時 true*/
  267. static boolean rbrackflag  = false ;    /* 数字処理中 ".)" 検出時 true*/
  268.  
  269. /*************************************************************************/
  270.  
  271. /**************************************/
  272. /*   insymbol() : symbolの読込メイン  */
  273. /**************************************/
  274.  
  275. void insymbol(void)
  276. {
  277.      skipspace() ;                      /* 空白読み飛ばし             */
  278.      switch(chartb[ch].chartp) {
  279.        case letter  : identifier()  ;  break; /* 名前の  処理         */
  280.        case number  : innumber()    ;  break; /* 数字の  処理         */
  281.        case chstrquo: strings()     ;  break; /* 文字列  処理         */
  282.        case chcolon : colonch()     ;  break; /* : の    処理         */
  283.        case chperiod: periodch()    ;  break; /* . の    処理         */
  284.        case chlt    : ltch()        ;  break; /* < の    処理         */
  285.        case chgt    : gtch()        ;  break; /* > の    処理         */
  286.        case chlparen: lparch()      ;  break; /* ( の    処理         */
  287.        case chrparen: rparch()      ;  break; /* ) の    処理         */
  288.        case chcoment: skipcomment() ;  break; /* 注釈の  処理         */
  289.        case special : specialch()   ;  break; /* 特殊文字処理         */
  290.        case illegal : illegch()     ;  break; /* 不当文字処理         */
  291.     /* case chspace :                   ---> このcase分岐はあり得ない */
  292.      };
  293. }
  294.  
  295. /**************************************/
  296. /*  skipspace() : 空白読み飛ばし      */
  297. /**************************************/
  298. static void skipspace(void)
  299. {
  300.      while(chartb[ch].chartp == chspace)
  301.       nextch();
  302. }
  303.  
  304. /**************************************/
  305. /*    nextch() : 次の1字読込処理      */
  306. /**************************************/
  307. static void nextch(void)
  308. {
  309.   static boolean eofflag  = false ;     /* EOF検出時  true            */
  310.   int lch ;
  311.  
  312.      if(eofflag) {
  313.       pcerr(610,"") ;                   /* EOF検出                    */
  314.       term() ;                          /* 終了処理                   */
  315.      }
  316.  
  317.      if(eolnflag) {                    /* 前の文字が行の終わりだった時*/
  318.       lineno++;
  319.       do ;
  320.        while((lch=getc(passource)) == ' '); /* 空白読み飛ばし         */
  321.      }
  322.  
  323.      if(!eolnflag) lch = getc(passource) ;
  324.  
  325.      eofflag  = feof(passource) ;
  326.      eolnflag = (lch == '\n') ;
  327.      ch = (eofflag)                     /* EOFの時は  読込文字を空白  */
  328.            ? ' ' : lch ;
  329.  
  330. }
  331.  
  332. /**************************************/
  333. /*     identifier() : 名前の処理      */
  334. /**************************************/
  335. static void identifier(void)
  336. {
  337.   int k=0;
  338.   int i;
  339.   enum chtp wktype ;
  340.  
  341.      for(i=0;i<=MaxIDlng;i++)          /* null クリア                */
  342.       id[i]='\0';
  343.                              /***** 高速化のためにポインタを使う  *****/
  344.      do {
  345.       if(k<MaxIDlng)                    /* 最大識別長まで格納         */
  346.        *(id+k++)=(('A'<=ch) && (ch<='Z'))  ? (char)ch+' ' : (char)ch ;
  347.                                         /* 大文字を小文字に変換       */
  348.       nextch();
  349.       } while(((wktype=(*(chartb+ch)).chartp) == letter) ||
  350.           ( wktype                        == number)) ;
  351.  
  352.       for(i=*(frw+k-1); i<*(frw+k);i++) { /* 予約語テーブルサーチ     */
  353.        if(!strcmp(id,(*(reswd+i)).rw)) {  /* 予約語である時           */
  354.     sy = (*(reswd+i)).rsy ;           /* 対応したsymbolを返す     */
  355.         op = (*(reswd+i)).rop ;
  356.         return;
  357.        }
  358.       }
  359.       sy = ident;                       /* 予約語以外の時は、ident    */
  360.       op = noop;
  361. }
  362.  
  363. /**************************************/
  364. /*     innumber() : 数字の処理        */
  365. /**************************************/
  366. static void innumber(void)
  367. {
  368.   char digit[Maxdiglng+1];
  369.   char expdigit[Maxdiglng+1];
  370.   csp *lvp ;
  371.   int i=0 ;
  372.   int k   ;
  373.   int w   ;
  374.   float realvalue ;
  375.   char *stopstring ;
  376.  
  377.      op = noop ;
  378.  
  379.      for(w=0;w<=Maxdiglng;w++)          /* null クリア                */
  380.       digit[w]='\0';
  381.  
  382.      do {
  383.       if(i < Maxdiglng) digit[i] = (char)ch ;/* 最大数字長以下の時格納*/
  384.       i++ ;
  385.       nextch() ;
  386.      } while(chartb[ch].chartp == number) ;
  387.  
  388.      if((ch != '.') && (ch != 'e') && (ch != 'E')){ /* real型でない時 */
  389.       val.ival =chtoint(i,digit) ;      /*  整数値に変換              */
  390.       return ;
  391.      }
  392.  
  393.      k=i ;
  394.      if(ch == '.') {                    /* 小数点の時                 */
  395.       val.ival = chtoint(i,digit);      /* 整数値に変換(値チェック)   */
  396.       if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納   */
  397.       k++ ;
  398.       nextch() ;
  399.       period2flag = (ch == '.') ;       /* ".."                       */
  400.       rbrackflag  = (ch == ')') ;       /* ".)"  ] の代替表現         */
  401.       if(period2flag || rbrackflag) {   /* ".." または ".)" の時      */
  402.        return ;
  403.       }
  404.       if(chartb[ch].chartp != number)   /* .の次の文字が数字以外      */
  405.        pcerr(201,"") ;                  /* 実数の表記に誤りがある     */
  406.       else {
  407.        do {
  408.         if(k < Maxdiglng) digit[k] = (char)ch ;
  409.         k++ ;
  410.         nextch() ;
  411.        } while(chartb[ch].chartp == number) ;
  412.       }
  413.      }
  414.  
  415.      if((ch == 'e') || (ch == 'E')) {   /* eの時                      */
  416.       if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納   */
  417.       k++ ;
  418.       nextch() ;
  419.       if((ch=='+') || (ch=='-')) {      /* e の次が+ - の時           */
  420.        if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納  */
  421.        k++ ;
  422.        nextch() ;
  423.       }
  424.       if(chartb[ch].chartp != number)
  425.        pcerr(201,"") ;                  /* 実数の表記に誤り           */
  426.       else {
  427.        i = 0;
  428.        do {
  429.         if(k < Maxdiglng) digit[k]    = (char)ch ;
  430.         if(i < Maxdiglng) expdigit[i] = (char)ch ;
  431.         k++ ;
  432.         i++ ;
  433.         nextch() ;
  434.        } while(chartb[ch].chartp == number) ;
  435.        chtoint(i,expdigit) ;            /* 指数部の大きさチェック     */
  436.       }
  437.      }
  438.  
  439.      if(k > Maxdiglng) {
  440.       pcerr(207,inttoch((long)Maxdiglng));/*  実数の桁数が範囲を越えている*/
  441.       strcpy(digit,"0.0");              /*  0.0 とする                */
  442.      }
  443.  
  444.      sy = realconst ;
  445.      lvp = (csp*)Malloc(sizeof(csp)) ;
  446.      lvp->cclass = real ;
  447.      val.valp = lvp ;                   /* 実数型の定数アドレスを設定 */
  448.      lvp->c.rval = (char*)Malloc(k+1);
  449.      *(lvp->c.rval) = ' ' ;             /* 先頭は符号エリア           */
  450.      strcpy(lvp->c.rval+1,digit) ;      /* 転送                       */
  451.      realvalue = (float)strtod(lvp->c.rval, &stopstring) ;
  452.       /* 実数変換エラーが起きるか判定 エラーとなればsignalで登録した
  453.          エラー処理関数に飛んでいく     */
  454. }
  455.  
  456. /*****************************************/
  457. /* real_err() : 実数変換エラーの時の処理 */
  458. /*  init内のsignal関数で登録される       */
  459. /*****************************************/
  460. void real_err(int sig, int subcode)
  461. {
  462.      pcerr(208,"") ;
  463.      signal(SIGFPE,real_err) ;          /* 再登録                     */
  464. }
  465.  
  466. /*****************************************/
  467. /* chtoint() : 文字から整数への変換処理  */
  468. /*****************************************/
  469. static long chtoint(int i,char *digit)
  470. {
  471.   long value ;
  472.   int j ;
  473.  
  474.      sy = intconst ;
  475.      value = 0  ;
  476.      for(j=0;j<i;j++) {                 /* 文字を整数に変換           */
  477.       if(value <= (Maxint - (digit[j]-'0')) / 10  ) /* 上限チェック   */
  478.        value = value*10 + (digit[j]-'0') ;
  479.       else {
  480.        pcerr(203,inttoch(Maxint)) ;     /* 符号なし整数がmaxintより大きい*/
  481.        return(0)        ;
  482.       }
  483.      }
  484.      return(value) ;
  485. }
  486.  
  487. /**************************************/
  488. /*     strings() : 文字列の処理       */
  489. /**************************************/
  490. static void strings(void)
  491. {
  492.   char string[Maxstrlng+1] ;
  493.   char *heapstring ;
  494.  
  495.      lgth = 0 ;
  496.      sy   = stringconst ;
  497.      op   = noop ;
  498.  
  499.      do {
  500.       do {
  501.        nextch() ;
  502.        if(lgth<Maxstrlng) string[lgth]=(char)ch;/* 最大文字列長以下の時格納 */
  503.        lgth++ ;
  504.       } while((!eolnflag) && (ch != '\'')) ;
  505.       if(eolnflag) pcerr(202,"") ;      /* 文字列定数は行を越えてはならない */
  506.       else nextch() ;                   /* 'の時、次の文字を読む             */
  507.      } while(ch == '\'') ;              /* 'が2続くときはもう一度繰り返す   */
  508.  
  509.      lgth-- ;                           /* 最後の'を取り除く                */
  510.      if(lgth==0) pcerr(205,"") ;        /* 文字長0の文字列は許されない      */
  511.      else if(lgth == 1)
  512.       val.ival = (long)string[0];       /* 1文字の時は、その値をvalに入れる */
  513.      else {                             /* 2文字以上の時                    */
  514.       val.valp = (csp*)Malloc(sizeof(csp)) ;
  515.       val.valp->cclass = strg ;
  516.       if(lgth > Maxstrlng) {            /* 最大文字列長を越えている時       */
  517.        pcerr(602,inttoch((long)Maxstrlng)) ; /* 文字列の最大長を越えている  */
  518.        lgth = Maxstrlng ;               /* 最大文字列長までを有効とする     */
  519.       }
  520.       string[lgth] = '\0' ;             /* nullで終わる文字列とする         */
  521.       heapstring = (char*)Malloc(lgth+1) ;/* 文字列長分のエリアを確保       */
  522.       strcpy(heapstring,string) ;
  523.       val.valp->c.sval = heapstring ;
  524.      }
  525. }
  526.  
  527. /**************************************/
  528. /*     colonch() : :(コロン) の処理      */
  529. /**************************************/
  530. static void colonch(void)
  531. {
  532.      op = noop;
  533.      nextch();
  534.      if(ch == '=') {                    /* ':='                       */
  535.       sy = becomes;                     /*   becomes  と する         */
  536.       nextch();
  537.      }
  538.      else sy = colon ;                  /* ':'  colon と する         */
  539. }
  540.  
  541. /**************************************/
  542. /*     lparch() : ( の処理            */
  543. /**************************************/
  544. static void lparch(void)
  545. {
  546.      op = noop   ;
  547.      nextch();
  548.      if(ch == '*') skipcomment();       /* '(*'   注釈                */
  549.      else if(ch == '.') {               /* '(.'   [ の代替表現        */
  550.       nextch()    ;
  551.       sy = lbrack ;
  552.      }
  553.      else  sy = lparent;
  554. }
  555.  
  556. /**************************************/
  557. /*     rparch() : ) の処理            */
  558. /**************************************/
  559. static void rparch(void)
  560. {
  561.      op = noop;
  562.      nextch();
  563.      if(rbrackflag) {                   /* 数字処理中 ".)"を見つけた時*/
  564.       sy = rbrack  ;                    /* 数字処理中 .. を見つけた時 */
  565.       rbrackflag = false ;
  566.      }
  567.      else sy = rparent;
  568. }
  569.  
  570. /*******************************************/
  571. /* skipcomment() : コメントの読み飛ばし処理*/
  572. /*    *) または } がコメントの終わり       */
  573. /*        ただし } は、シフトJISの2バイト目*/
  574. /*          になり得るので、その処理もする */
  575. /*******************************************/
  576. static void skipcomment(void)
  577. {
  578.      nextch();
  579.      if(ch=='$') {
  580.       options();                        /* $の後にはオプション が来る     */
  581.       if(iskanji(ch)) {
  582.        nextch() ;
  583.        nextch() ;
  584.       }
  585.      }
  586.      if(iskanji(ch)) {
  587.       nextch() ;
  588.       nextch() ;
  589.      }
  590.      do {
  591.       while((ch != '*') && (ch != '}')) {
  592.        if(iskanji(ch)) {
  593.         nextch() ;
  594.         nextch() ;
  595.        }
  596.        else nextch() ;
  597.       }
  598.       if(ch == '}') break   ;           /* }  ならコメント終わり      */
  599.       else {
  600.        if(iskanji(ch)) {
  601.         nextch() ;
  602.         nextch() ;
  603.        }
  604.        else nextch() ;
  605.       }
  606.      } while(ch != ')') ;
  607.      nextch();
  608.      insymbol();                        /* 有効なsymbolを見つける(再帰)*/
  609. }
  610.  
  611. /*****************************************/
  612. /* options() : オプション設定処理        */
  613. /*             d+ d- t+ t-               */
  614. /*****************************************/
  615. static void options(void)
  616. {
  617.   char optionchar ;
  618.  
  619.      nextch() ;
  620.      optionchar = (char)ch ;
  621.      if((ch=='d') || (ch=='t')) nextch();
  622.      else return ;
  623.      if((ch=='+') || (ch=='-'))
  624.       if(optionchar=='d') debug = (ch=='+') ;
  625.       else
  626.        if(ch=='+') gen1(iTRA,1) ;       /* トレースオン  tra  1       */
  627.        else        gen1(iTRA,2) ;       /* トレースオフ  tra  2       */
  628. }
  629.  
  630. /****************************************/
  631. /* periodch() :  .(ピリオド)の処理        */
  632. /****************************************/
  633. static void periodch(void)
  634. {
  635.      op = noop;
  636.      nextch();
  637.      if(period2flag) {
  638.       sy = period2 ;                    /* 数字処理中 .. を見つけた時 */
  639.       period2flag = false ;
  640.      }
  641.      else if(ch == '.') {               /* 今 .. だった時             */
  642.        sy = period2 ;                   /* ..  と する                */
  643.        nextch();
  644.      }
  645.      else if(ch == ')') {               /* 今 .) だった時             */
  646.       sy = rbrack ;                     /*  ]   とする                */
  647.       nextch()    ;
  648.      }
  649.      else sy = period ;                 /* . 単独の時は . とする      */
  650. }
  651.  
  652. /****************************************/
  653. /*        ltch() :  < の処理            */
  654. /****************************************/
  655. static void ltch(void)
  656. {
  657.      nextch();
  658.      sy=relop;
  659.      if(ch == '=') {                    /* '<='                       */
  660.       op = leop;                        /*       less equal と する   */
  661.       nextch();
  662.      }
  663.      else if(ch == '>') {               /* '<>'                       */
  664.       op = neop ;                       /*       not equal  と する   */
  665.       nextch()  ;
  666.      }
  667.      else op = ltop ;                   /* '<'   less than とする     */
  668. }
  669.  
  670. /****************************************/
  671. /*        gtch() :  > の処理            */
  672. /****************************************/
  673. static void gtch(void)
  674. {
  675.      nextch();
  676.      sy = relop;
  677.      if(ch == '=') {                    /* '>='                       */
  678.       op = geop;                        /*   grater equal と する     */
  679.       nextch();
  680.      }
  681.      else op = gtop ;                   /* '>'  grater than とする    */
  682. }
  683.  
  684. /****************************************/
  685. /*      specialtch() : 特殊文字の処理   */
  686. /****************************************/
  687. static void specialch(void)
  688. {
  689.      sy = chartb[ch].ssy ;              /* その文字のsymbol           */
  690.      op = chartb[ch].sop ;              /* その文字の演算子           */
  691.      nextch()            ;
  692. }
  693.  
  694. /****************************************/
  695. /*        illegch() : 不当文字の処理    */
  696. /****************************************/
  697. static void illegch(void)
  698. {
  699.   char wch[3] ;
  700.  
  701.      sy = othersy;
  702.      op = noop   ;
  703.      wch[0] = (char)ch ;
  704.      if(iskanji(ch)) {                  /* 漢字の時 漢字埋め込み処理  */
  705.       nextch() ;
  706.       wch[1] = (char)ch   ;
  707.       wch[2] = '\0' ;
  708.      }
  709.      else wch[1] = '\0' ;
  710.      pcerr(30,wch)      ;               /* 不当文字が現れた           */
  711.      nextch()           ;
  712. }
  713.